const nextFunction = {
  nextRegister(a) {
    var args = arguments;
    var count = 0;
    var comm = {};
    return new Promise((reovle, reject) => {
      function nextTime() {
        count++;
        if (count < args.length) {
          if (args[count] && Object.prototype.toString.call(args[count]) == '[object Function]') {
            if ((args.length - 1) == count) {
              args[count](comm, nextTime).then(res => {
                reovle(res)
              });
            } else {
              args[count](comm, nextTime)
            }
          }
        }
      }
      if (args[count] && Object.prototype.toString.call(args[count]) == '[object Function]') {
        args[count](comm, nextTime)
      }
    })
  },
  nextRegisterNoback(a) {
    var args = arguments;
    var count = 0;
    var comm = {};
    return new Promise((reovle, reject) => {
      function nextTime() {
        count++;
        if (count < args.length) {
          if (args[count] && Object.prototype.toString.call(args[count]) == '[object Function]') {
    
              args[count](comm, nextTime)
            
          }
        }
      }
      if (args[count] && Object.prototype.toString.call(args[count]) == '[object Function]') {
        args[count](comm, nextTime)
      }
    })
  },
  waitAll() {
    var args = arguments;
    var count = 1;
    var i;
    return new Promise(function (resolve) {
      if (count < args.length) {
        for (i = 0; i < args.length; i++) {
          args[i]().then(function (res) {
            count++;
            if (count == args.length) {
              resolve(true)
            }
          });
        }

      }
    });
  }
}
export default nextFunction
